<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>myOrder</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
    <link rel="stylesheet" th:href="@{/bootstrap.min.css}" />
    <script th:src="@{/vue.js}"></script>
</head>
<body>

<div th:insert="publicHeader"/>
<script th:src="@{/publicHeader.js}"></script>



<div class="container-fluid" id="app" style="margin-top: 180px;margin-bottom: 100px">


    <div class="container col-md-12" v-if="orderList.length<=0" >
        <h3 style="text-align: center">还没有订单,快去购买吧~</h3>
    </div>



    <div class="row" v-if="orderList.length>0">
        <div class="container">
            <div v-for="order in orderList">
                <div class="row" style="height: 40px ;line-height: 40px">
                    <div class="col-md-12">
                        <p style="background-color: #CCCCCC; font-size: 15px; line-height: 40px">订单编号:{{order.orderNum}} 下单时间:{{order.orderTime}}  总金额:{{order.totalPrice}}元</p>
                    </div>
                </div>
                <div class="row p-3">
                    <div class="col-md-10 col-md-offset-1">
                        <table class="table">
                            <tr>
                                <th>图片</th>
                                <th>名称</th>
                                <th>购买数量</th>
                                <th>金额</th>
                            </tr>
                            <tr v-for="item in order.orderItemList">
                                <td>
                                    <img style="height: 60px;width: 60px" :src="item.productImgsrc">
                                </td>
                                <td v-text="item.productName" style="vertical-align: middle">名称</td>
                                <td v-text="item.buyCount" style="vertical-align: middle">购买数量</td>
                                <td v-text="item.sumPrice"  style="vertical-align: middle">金额</td>
                            </tr>
                        </table>
                    </div>
                    <div class="col-md-1">
                        <!--订单状态 1.未支付  2.已支付  3.已取消-->
                        <button v-if="order.status == 1" class="btn btn-primary" @click="updateStatus(order.id,2)">去支付</button>
                        <button v-if="order.status == 1" class="btn btn-primary" @click="updateStatus(order.id,3)">取消</button>
                        <button v-if="order.status == 2" class="btn btn-primary">已支付</button>
                        <button v-if="order.status == 3" class="btn btn-primary">已取消</button>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-md-12 col-md-offset-5 col-lg-offset-4col-xl-offset-5" >
            <ul class="pagination justify-content-center">
                <li><a href="javascript:void(0)" @click.prevent="go(currentPage-1)">&laquo;</a></li>
                <li><a href="javascript:void(0)" v-for="n in totalPages" v-text="n" @click.prevent="go(n)">n</a></li>
                <li><a href="javascript:void(0)" @click.prevent="go(currentPage+1)" >&raquo;</a></li>
            </ul>
        </div>
    </div>






</div>

<script>

    console.log(".........myOrder...........")

    new Vue({
        el: "#app"
        ,
        data: {
            orderList:[],

            currentPage:1,
            pageSize:2,
            total:0,
            totalPages:0
        }
        ,
        methods: {

            initOrderList(){
                let _this = this;
                let params={
                    currentPage: this.currentPage,
                    pageSize : this.pageSize
                }
                $.post("/order/all",params,function (data) {

                    console.log(data)
                    _this.orderList = data.records;
                    _this.currentPage=data.current;
                    _this.pageSize=data.size;
                    //数据总量
                    _this.total=data.total;
                    //总页数
                    _this.totalPages=data.pages;
                })
            }
            ,
            updateStatus(orderId,newStatus){

                let params={
                    orderId:orderId,
                    newStatus:newStatus
                }

                console.log(params)

                let _this =this;

                $.post("/order/updateStatus",params,function (data) {
                    //状态修改完成后刷新页面数据
                    _this.initOrderList();
                })


            }
            ,
            go(pageNum){
                //小于1 或者 大于total 或者 仍获取当前页数据 直接返回
                if(pageNum<1 || pageNum>this.totalPages || pageNum==this.currentPage){
                    console.log(pageNum + " 无效页码值")
                    return;
                }

                console.log(pageNum)
                this.currentPage = pageNum;
                this.initOrderList();
            }

        }
        ,
        created(){
            this.initOrderList();
        }

    });


</script>


<div th:insert="publicFooter"/>
<script th:src="@{/publicFooter.js}"></script>


</body>
</html>